package com.zy.service.bs.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.zy.dao.bs.IntegralDetailDao;
import com.zy.entity.enums.StatusEnum;
import com.zy.entity.bs.IntegralDetail;
import com.zy.pojo.query.bs.IntegralDetailQuery;
import com.zy.pojo.vos.common.PageVo;
import com.zy.service.base.impl.BaseServiceImpl;
import com.zy.service.bs.IntegralDetailService;
import com.zy.utils.DateUtil;

@Service("integralDetailService")
public class IntegralDetailServiceImpl extends BaseServiceImpl<IntegralDetail> implements IntegralDetailService {

	@Autowired
	private IntegralDetailDao integralDetailDao;

	@Override
	public PageVo pageIntegralDetail(IntegralDetailQuery integralDetailQuery, Integer start, Integer limit) {
		return new PageVo(start, limit, this.integralDetailDao.countIntegralDetail(integralDetailQuery), this.integralDetailDao.listIntegralDetail(integralDetailQuery, start, limit));
	}

	@Override
	public void saveIntegralDetail(IntegralDetail integralDetail) {
		long time = DateUtil.getTime();

		this.integralDetailDao.save(integralDetail);
	}
	
	@Override
	public void updateIntegralDetail(IntegralDetail integralDetail) {
		this.integralDetailDao.updateByPrimaryKeySelective(integralDetail);
	}

	@Override
	public void removeIntegralDetail(long id) {
		try {
			this.integralDetailDao.removeByPrimaryKey(id);
		} catch (Exception e) {
			log.info(e.getMessage(),e);
			IntegralDetail integralDetail = new IntegralDetail();
			integralDetail.setId(id);
			this.integralDetailDao.updateByPrimaryKeySelective(integralDetail);
		}
	}

	@Override
	public void recover(long id) {
		IntegralDetail integralDetail = new IntegralDetail();
		integralDetail.setId(id);

		this.integralDetailDao.updateByPrimaryKeySelective(integralDetail);
	}

	@Override
	public PageVo appList(Long userId, Integer start, Integer limit) {
		return new PageVo(start, limit, this.integralDetailDao.appCount(userId), this.integralDetailDao.appList(userId, start, limit));
	}

}
